﻿using Mysoft.Data.CacheManager.IService;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Mysoft.Domain.Basic
{
    /// <summary>
    /// 注入Domain服务
    /// </summary>
    /// <typeparam name="TDomain"></typeparam>
    public class DomainService<TDomain> where TDomain : DomainBase
    {
        /// <summary>
        ///  注入全局实例
        /// </summary>
        /// <param name="instance"></param>
        public DomainService(IServiceProvider serviceProvider)
        {
            if (_Instance == null)
            {
                _Instance = serviceProvider;
            }
        }

        /// <summary>
        /// 全局实例对象
        /// </summary>
        private static IServiceProvider _Instance { get; set; }
        public TDomain Instance
        {
            get { return _Instance.GetService(typeof(TDomain)) as TDomain; }
        }
    }
}
